///
/// ArmyBodger 3
/// (c)2010 richyp
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArmyBodger.Core {
    /// <summary>
    /// A Collection of Upgrade objects
    /// </summary>
    public class UpgradeCollection : List<Upgrade> {
        /// <summary>
        /// Indexer to get an Upgrade by name
        /// </summary>
        /// <param name="name">The name of the Upgrade to get</param>
        /// <returns>The Upgrade object or null</returns>
        public Upgrade this[string name] {
            get {
                foreach (Upgrade upgrade in this) {
                    if (upgrade.Equipment != null && upgrade.Equipment.Name == name) {
                        return upgrade;
                    }
                }
                return null;
            }
        }
        /// <summary>
        /// Get a collection of Upgrade objects within this collection
        /// that are currently applied
        /// </summary>
        public UpgradeCollection AppliedUpgrades {
            get {
                UpgradeCollection applied = new UpgradeCollection();
                foreach (Upgrade upgrade in this) {
                    if (upgrade.Applied) {
                        applied.Add(upgrade);
                    }
                }
                return applied;
            }
        }
    }
}
